extends StateBase


var ownerNode:Funnel
@onready var timerCaseTime = $TimerCaseTime
@onready var timerValidTime:Timer = $TimerValidTime
@onready var timerCooldown:Timer = $TimerCooldown


func enter(obj):
	ownerNode = obj
	
	timerCaseTime.wait_time = ownerNode.shootCastTime
	timerValidTime.wait_time = ownerNode.shootValidTime
	timerCooldown.wait_time = ownerNode.shootCooldown
	
	timerCaseTime.timeout.connect(onCaseTimeOver)
	timerValidTime.timeout.connect(onValidTimeOver)
	timerCooldown.timeout.connect(onCooldownOver)
	
	timerCaseTime.start()
	
	
func onCaseTimeOver():
	timerValidTime.start()
	
	ownerNode.laser.show()
	ownerNode.laserCollisionShape.disabled = false
	
	
func onValidTimeOver():
	timerCooldown.start()
	
	ownerNode.laser.hide()
	ownerNode.laserCollisionShape.disabled = true
	
	
func onCooldownOver():
	ownerNode.stateMachine.removeState("Shoot", ownerNode)
	ownerNode.stateMachine.addState("Move", ownerNode)
	

func exit(obj):
	timerCaseTime.timeout.disconnect(onCaseTimeOver)
	timerValidTime.timeout.disconnect(onValidTimeOver)
	timerCooldown.timeout.disconnect(onCooldownOver)
	
	timerCaseTime.stop()
	timerValidTime.stop()
	timerCooldown.stop()


func run(delta, obj):
	pass

